package com.xd.cloud.common.listener;

import com.xd.cloud.common.GlobalConfig;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * @author wangtao
 * @class_name CloudVehicleListener
 * @description 项目初始化全局配置信息 详情在classpath :properties文件下
 * @create 2017/12/7
 */
public class CloudVehicleListener  implements ServletContextListener {

    public void contextInitialized(ServletContextEvent servletContextEvent) {
        ServletContext servletContext = servletContextEvent.getServletContext();
        WebApplicationContext webApplicationContext = WebApplicationContextUtils.getWebApplicationContext(servletContext);
        if(webApplicationContext != null){
            GlobalConfig globalConfig = webApplicationContext.getBean(GlobalConfig.class);

            globalConfig.loadProperties(servletContext);
        }
    }

    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
